Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for UTD error codes in [Sync]TimelineEvent #4070

Merged
merged 4 commits into from
Oct 21, 2024

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Oct 4, 2024

This PR takes the TimelineEventKind that was added in #4082, and adds a third enum variant which is specific to unable-to-decrypt events. We update the two methods which are responsible for decrypting encrypted events that have been received from the network (decrypt_sync_room_event and decrypt_room_event), and make them return a [Sync]TimelineEvent of the relevant kind instead of a megolm error.

Since pretty much everything downstream accesses UTD events via TimelineEventKind::raw(), we don't have to change much else to keep things working.

Part of #4048.

@richvdh richvdh force-pushed the rav/utds_in_timeline_event branch 3 times, most recently from 455bbd4 to c737e86 Compare October 4, 2024 11:24
Copy link

codecov bot commented Oct 4, 2024

Codecov Report

Attention: Patch coverage is 68.62745% with 16 lines in your changes missing coverage. Please review.

Project coverage is 84.80%. Comparing base (0c26988) to head (1cc4629).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-ui/src/notification_client.rs 0.00% 13 Missing ⚠️
...es/matrix-sdk-common/src/deserialized_responses.rs 66.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4070      +/-   ##
==========================================
- Coverage   84.84%   84.80%   -0.04%     
==========================================
  Files         269      269              
  Lines       28800    28827      +27     
==========================================
+ Hits        24434    24446      +12     
- Misses       4366     4381      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@richvdh richvdh force-pushed the rav/utds_in_timeline_event branch 8 times, most recently from bcd57e8 to ab28964 Compare October 10, 2024 17:08
@richvdh richvdh force-pushed the rav/utds_in_timeline_event branch 2 times, most recently from 03d4148 to 8fa3bf9 Compare October 11, 2024 15:36
@richvdh richvdh force-pushed the rav/utds_in_timeline_event branch from f702bc9 to bad2be9 Compare October 15, 2024 13:23
@richvdh richvdh changed the title WIP: support for UTD error codes in the timeline WIP: support for UTD error codes in [Sync]TimelineEvent Oct 15, 2024
@richvdh richvdh force-pushed the rav/utds_in_timeline_event branch 3 times, most recently from 06eff7f to d00c1a2 Compare October 16, 2024 16:55
@richvdh richvdh changed the title WIP: support for UTD error codes in [Sync]TimelineEvent Support for UTD error codes in [Sync]TimelineEvent Oct 16, 2024
@richvdh richvdh force-pushed the rav/utds_in_timeline_event branch 3 times, most recently from 0997324 to d838ed5 Compare October 17, 2024 15:59
When `decrypt_sync_room_event` fails to decrypt an event, return the UTD as a
`SyncTimelineEvent` instead of an Error.
@richvdh richvdh force-pushed the rav/utds_in_timeline_event branch from d838ed5 to 63b94a3 Compare October 21, 2024 11:53
@richvdh richvdh marked this pull request as ready for review October 21, 2024 11:54
@richvdh richvdh requested a review from a team as a code owner October 21, 2024 11:54
@richvdh richvdh requested review from stefanceriu and removed request for a team October 21, 2024 11:54
Copy link
Member

@stefanceriu stefanceriu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good to me 👍

// key; retry in a few.
wait *= 2;
} else {
trace!("Event could not be decrypted, but waiting longer is unlikely to help: {:?}", utd_info.reason);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels useful on the nse level, should we maybe promote it to at least info?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the failure will already be logged at warning in the crypto layer, so it's not immediately obvious that logging it again is right.

I'll bump this one to debug as a compromise for now.

matrix_sdk::deserialized_responses::TimelineEventKind::UnableToDecrypt {
utd_info, ..
} => {
trace!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, the actual error will be logged at warning, and in this case it's just replicating the previous behaviour (note the trace!("Encryption sync failed to decrypt the event: {err}"); just below).

I can change this if you feel strongly but it's not obvious to me that we should.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No no, that's quite okay, I didn't check the lower levels to see if we print it anywhere else.

When `decrypt_room_event` fails to decrypt an event, return the UTD as a
`TimelineEvent` instead of an Error.
Make the tests behave the same way as the network code, by returning UTDs
as `TimelineEventKind::UnableToDecrypt` instead of `TimelineEventKind::PlainText`.
@richvdh richvdh force-pushed the rav/utds_in_timeline_event branch from 89bd8c1 to 1cc4629 Compare October 21, 2024 16:11
@richvdh richvdh enabled auto-merge (rebase) October 21, 2024 16:11
@richvdh richvdh merged commit 3887c10 into main Oct 21, 2024
40 checks passed
@richvdh richvdh deleted the rav/utds_in_timeline_event branch October 21, 2024 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants